/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Dialogos;

import com.sun.corba.se.spi.ior.MakeImmutable;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;
import sun.misc.FormattedFloatingDecimal;

/**
 *
 * @author Pedro
 */
public class ParamXY extends JDialog
{

    JButton botaoOk;
    JButton botaoCancelar;
    JTextField txtX,txtY;
    JLabel labelX,labelY;
    private boolean ok;
    private int x;
    private int y;
    public ParamXY(JFrame owner)
    {
        super(owner, "Digite os parâmetros!");
        this.setLayout(new BorderLayout());
        JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(1, 4));
        JPanel p2 = new JPanel();
        p2.setLayout(new GridLayout(1,2));

        botaoOk = new JButton("OK");
        botaoOk.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ok = true;
                dispose();
            }
        });
        botaoCancelar = new JButton("Cancelar");
        botaoCancelar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ok = false;
                dispose();
            }
        });
        labelX = new JLabel("X:");
        try {
            txtX = new JFormattedTextField(new MaskFormatter("###.###"));
        } catch (ParseException ex) {
            Logger.getLogger(ParamXY.class.getName()).log(Level.SEVERE, null, ex);
        }

        labelY = new JLabel("Y:");
        try {
            txtY = new JFormattedTextField(new MaskFormatter("###.###"));
        } catch (ParseException ex) {
            Logger.getLogger(ParamXY.class.getName()).log(Level.SEVERE, null, ex);
        }



        p1.add(labelX);
        p1.add(txtX);
        p1.add(labelY);
        p1.add(txtY);
        p2.add(botaoOk);
        p2.add(botaoCancelar);
        this.add(p1,BorderLayout.CENTER);
        this.add(p2,BorderLayout.SOUTH);
        this.setSize(new Dimension(300,100));
        this.setModal(true);
        this.setVisible(true);

    }

    /**
     * @return the ok
     */
    public boolean isOk() {
        return ok;
    }
  
    /**
     * @return the y
     */
    public double getYV() {
        return Double.parseDouble(txtY.getText());
    }

    /**
     * @param y the y to set
     */
    public double getXV() {
        return Double.parseDouble(txtX.getText());
    }

}
